<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>点我发送</button>
  </body>
  <script>
    let ws = new WebSocket('ws://124.222.224.186:8800')
    /** 监听链接成功 */
    ws.onopen = () => {
      console.log('链接成功')
    }
    /** 监听链接失败 */
    ws.onerror = () => {
      console.log('链接失败')
    }
    /** 给服务器发送消息 */
    let btn = document.querySelector('button')
    btn.onclick = () => {
      ws.send('我很好')
    }
    /** 监听服务器返回的消息 */
    ws.onmessage = (e) => {
      console.log(e.data)
    }
  </script>
</html>
